<?php 
//Luu giu trang thai loc theo loai ho so
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
if(isset($_REQUEST['hdn_recordtype_filter'])){
	$v_recordtype_filter = $_REQUEST['hdn_recordtype_filter'];
} 
//Begin//Xay dung chuoi XML chua gi tri 
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}
$strXML = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
for ($i=0;$i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR);$i++){
	$strXML = $strXML ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	$strXML = $strXML .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
	$strXML = $strXML ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
}
$strXML = $strXML . "</data_list></root>";
//End//Lay danh sach cac the XML va gia tri tuong ung voi tung the do
//Ma ho so
//_write_log_file('tuyenntt.txt',$strXML);

$v_record_id = 0;
if(isset($_REQUEST['hdn_record_id'])){
	$v_record_id = intval($_REQUEST['hdn_record_id']);
}
//Trang thai chi tiet cua ho so
$v_status_detail = 61;
if(isset($_REQUEST['hdn_work'])){
	$v_status_detail = intval($_REQUEST['hdn_work']);
}
/* begin--nieuvv--010808---- xu ly lay ma cua hinh thuc ho so--*/
if($v_recordtype_filter == "001"){
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($strXML);
$table_struct_rax->record_delim = 'data_list';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_type_process_ = $table_struct_row["hinh_thuc_xu_ly"];
if($v_type_process_ == 'HGP')	// Huy giay phep 
{
	$v_status_detail = 71;
	$v_erase_license = "HUY_GIAY_PHEP";
}
if($v_type_process_ == 'THGP')	// Thu hoi giay phep 
{
	$v_status_detail = 61;
	$v_erase_license = "THU_HOI_GIAY_PHEP";
}
}
/*-----the--end--nieuvv--010808---------*/
$v_status = $arr_record_status[0][0];
$v_recordtype = $_SESSION['onegate_current_recordtype'];
$v_staff_id = $_SESSION['staff_id'];
//echo htmlspecialchars($strXML) ;
if(_is_sqlserver()){
	$license_xml_data_id = _save_XML_to_database('T_TEMP_FILE', 'PK_TEMP_FILE', 'C_TEXT', $strXML);
	//Cap nhat noi dung 
	$sql = "Exec Onegate_PostLicenseUpdate " ;
	$sql = $sql . " '" .  $v_record_id."'";
	$sql = $sql . "," .  $license_xml_data_id ;
	//echo $sql; exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql); 
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	
	//Cap nhat cong viec
	$v_worktype = "XU_LY_SAU_GIAI_QUYET";
	$sql = "Exec Onegate_RecordWorkSystemUpdate " ;
	$sql = $sql . " '" .$v_record_id."'";
	$sql = $sql . "," . $v_staff_id;
	$sql = $sql . ",'" .$v_worktype."'" ;
	//echo $sql; exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql);
	// Cap nhat tinh trang ho so C_CURRENT_STATUS	--010808--nieuvv
	if($v_recordtype_filter == "001"){	
		$sql = "Exec Onegate_RecordCurrentStatusUpdate " ;
		$sql = $sql . $v_record_id;
		$sql = $sql . ",'" . $v_erase_license."'";
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$rs = $ado_conn->GetRow($sql);	
	}
	// the end nieuvv-010808
	
	//Cap nhat trang thai chi tiet
	$sql = "Exec Onegate_RecordStatusDetailUpdate " ;
	$sql = $sql . $v_record_id;
	$sql = $sql . "," . $v_status_detail;
//	echo $sql; exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql);	
}
sleep(0);
if (!is_null($v_error) && $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_goto_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="DISPLAY_ALL_RECORD_ARCHIVES">
	<input type="hidden" name="hdn_record_id" value="<?php echo $v_record_id;?>">
	<input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter; ?>">
</form>
<Script language="javascript">
	document.forms(0).submit();
</Script>